import LibGenerateTestUserSig from './lib-generate-test-usersig-es.min.js';

const logkey = 'xone-tcloud'

export let tcloud = {
  init(userId,sdkAppId,userSig) {
    if(userSig&&sdkAppId) {
      console.log(logkey, 'init', userId, sdkAppId, userSig)
      this.userId = userId
      this.sdkAppId = sdkAppId
      this.userSig = userSig
    }else{
      console.log(logkey, 'init', userId, this.sdkAppId, this.secretKey)
      this.userId = userId
      this.userSig = this.getUserSig(this.userId, this.sdkAppId, this.secretKey, this.expireTime)
    }
  },
  getUserSig(userId, sdkAppId, secretKey, expireTime) {
    console.log(logkey, 'getUserSig', userId, sdkAppId, secretKey, expireTime)
    const generator = new LibGenerateTestUserSig(sdkAppId, secretKey, expireTime)
    return generator.genTestUserSig(userId)
  }
}

export default function($x, {
	tcloudExtend
}={}, app) {
	Object.assign(tcloud, tcloudExtend||{})
	$x.tcloud = tcloud
}